from http_server import Response

from log import Log

log = Log(tag='Upgrade')


class UpgradeController:
    def post(self, req):
        body_str = req.body.read_all_as_string()
        filename = req.headers['X-FileName']
        log.info('Upgrade file[%s]' % filename)
        print('Body len=[%s]' % len(body_str))
        print(body_str)
        with open(filename, 'w') as f:
            f.write(body_str)
        log.info('Upgrade file[%s] Success!' % filename)
        return Response(status=200, body=b'OK')

